package com.zklh.book.system.common.model;

import java.io.Serializable;

/**
 * 定义返回结果的格式, 所有请求都要返回该结构
 *
 * @author 坐看落花
 * @version 1.0
 * @date 2021/3/20 19:56
 */
public class RestResponse<T> implements Serializable {


    private Boolean success;

    private int code;

    private String msg;

    private T data;


    public static <T> RestResponse<T> success(T data){
        return new RestResponse<>(true, 200, "success", data);
    }

    public static <T> RestResponse<T> error(int code, String msg){
        return new RestResponse<>(false, code, msg, null);
    }


    public Boolean getSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public RestResponse() {
    }

    public RestResponse(Boolean success, int code, String msg, T data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
